## coding: utf-8
#function: Stack sparse matrices vertically (row wise)
##manual: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.vstack.html#scipy.sparse.vstack
def incrementalBuildByRow(rowA, rowB):
    from scipy.sparse import vstack
    rowUnion = vstack([rowA, rowB])
    return rowUnion

## test code:
def incrementalBuildByRowTest():
    from scipy.sparse import csr_matrix
    sparsev1 = csr_matrix([0, 2, 0, 0])
    sparsev2 = csr_matrix([2, 0, 1, 0])
    ll = incrementalBuildByRow(sparsev1, sparsev2)
    print "type", type(ll)
    print ll.todense()

if __name__ == "__main__":
    incrementalBuildByRowTest()